"""
测试图表生成器功能
"""
import asyncio
from servers.juyuan_mcp_server import generate_report


async def test_llm_report_generation():
    # 测试数据
    test_data = {
        "title": "诺安多策略混合A最新十大重仓股分析报告",
        "description": "本报告分析了诺安多策略混合A（基金代码：320016）截至2025年9月30日的前十大重仓股，包括行业分布和持仓份额。",
        "data": [
            {
                "股票名称": "冠中生态",
                "股票代码": "300948",
                "持股数量_股": "1379200",
                "市值_元": "22246496",
                "占资产净值比例": "0.66%"
            },
            {
                "股票名称": "欣龙控股",
                "股票代码": "000955",
                "持股数量_股": "3323000",
                "市值_元": "18309730",
                "占资产净值比例": "0.54%"
            },
            {
                "股票名称": "远翔新材",
                "股票代码": "301300",
                "持股数量_股": "460500",
                "市值_元": "18005550",
                "占资产净值比例": "0.53%"
            },
            {
                "股票名称": "福建水泥",
                "股票代码": "600802",
                "持股数量_股": "2947041",
                "市值_元": "17475953.13",
                "占资产净值比例": "0.52%"
            },
            {
                "股票名称": "宁波色母",
                "股票代码": "301019",
                "持股数量_股": "930286",
                "市值_元": "17647525.42",
                "占资产净值比例": "0.52%"
            },
            {
                "股票名称": "三超新材",
                "股票代码": "300554",
                "持股数量_股": "666000",
                "市值_元": "17129520",
                "占资产净值比例": "0.51%"
            },
            {
                "股票名称": "富春染织",
                "股票代码": "605189",
                "持股数量_股": "1099260",
                "市值_元": "17423271",
                "占资产净值比例": "0.51%"
            },
            {
                "股票名称": "百川畅银",
                "股票代码": "300614",
                "持股数量_股": "1069600",
                "市值_元": "16803416",
                "占资产净值比例": "0.50%"
            },
            {
                "股票名称": "合力科技",
                "股票代码": "603917",
                "持股数量_股": "1205040",
                "市值_元": "16894660.8",
                "占资产净值比例": "0.50%"
            },
            {
                "股票名称": "海波重科",
                "股票代码": "300517",
                "持股数量_股": "1391110",
                "市值_元": "16874164.3",
                "占资产净值比例": "0.50%"
            }
        ],
        "risk_warning": "本报告基于公开数据生成，仅供参考。投资有风险，决策需谨慎。"
    }

    # 测试报告生成 - 使用await调用异步函数
    # md_content = await generate_report(test_data, "查询诺安多策略混合A最新十大重仓股票，看下它的分布行业和份额，给出分析报告")
    # print("md报告生成完成")
    #
    # with open('report_llm_1.html', 'w', encoding='utf-8') as f:
    #     f.write(md_content)
    #
    # print("文件已保存为 report_llm_1.html，请用浏览器打开")

    # ppt_content = await generate_report(test_data,
    #                                      "查询诺安多策略混合A最新十大重仓股票，看下它的分布行业和份额，给出分析报告", report_type="ppt")
    # print("ppt报告生成完成")
    #
    # with open('report_llm_2.html', 'w', encoding='utf-8') as f:
    #     f.write(ppt_content)
    #
    # print("文件已保存为 report_llm_2.html，请用浏览器打开")

    html_content = await generate_report(test_data,
                                         "查询诺安多策略混合A最新十大重仓股票，看下它的分布行业和份额，给出分析报告",
                                         report_type="html")
    print("html报告生成完成")

    with open('report_llm_3.html', 'w', encoding='utf-8') as f:
        f.write(html_content)

    print("文件已保存为 report_llm_3.html，请用浏览器打开")


if __name__ == "__main__":
    # 运行异步函数
    asyncio.run(test_llm_report_generation())